package com.czx.controller;


import com.czx.common.security.UserTokenThreadLocal;
import com.czx.service.SysMessageService;
import com.czx.vo.NoticeVo;
import com.czx.vo.UserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class NoticeController {
    @Autowired
    private SysMessageService sysMessageService;
    @RequestMapping("/notice")
    public String notice(Model model){
        UserToken userToken = UserTokenThreadLocal.get();
        //通过id查询所有的未读通知
        Integer noticeUnreadCount = sysMessageService.SysMessage(userToken.getUser().getId());
        model.addAttribute("noticeUnreadCount",noticeUnreadCount);
        //查询评论
        NoticeVo commentNotice = sysMessageService.getNotice(userToken.getUser().getId(), 0);
        //查询关注
        NoticeVo followNotice = sysMessageService.getNotice(userToken.getUser().getId(), 1);
        //查询点赞
        NoticeVo likeNotice = sysMessageService.getNotice(userToken.getUser().getId(),2);

        model.addAttribute("commentNotice",commentNotice);
        model.addAttribute("followNotice",followNotice);
        model.addAttribute("likeNotice",likeNotice);

        return "site/notice";
    }
}
